# -*- coding: utf-8 -*-
# @File      :面试题
# @Author    :liaogan
# @Datetime  :2023/11/10 16:23


def print_most_common_letter(filename):
    with open(filename, 'r') as file:
        data = file.read()
        # print(data.lower())
        # print(data.isalpha())

        # 将字符串转换为小写并删除非字母字符
    clean_data = ''.join(c for c in data if c.isalpha()).lower()
    print(clean_data)

    # 初始化字母计数为0，以及字母及其计数
    letter_count = {}
    for letter in clean_data:
        print(letter)
        if letter in letter_count:
            letter_count[letter] += 1
        else:
            letter_count[letter] = 1

            # 找到出现次数最多的字母
    max_count = max(letter_count.values())
    most_common_letters = [letter for letter, count in letter_count.items() if count == max_count]

    if len(most_common_letters) == 1:
        return most_common_letters[0] + " " + str(max_count)
    else:
        return most_common_letters + " " + str(max_count)

if __name__ == '__main__':
    print(print_most_common_letter(r"D:\Python2022\python培训\华为面试题\test.txt"))